﻿namespace EyeOpen.Web
{
	using System.Linq;
	using System.Web.UI.WebControls;

	public static class DropDownListExtensions
	{
		public static void SelectByText(this DropDownList dropDownList, string text)
		{
			dropDownList.DataBound +=
				(s, e) =>
					{
						var item = dropDownList.Items.Cast<ListItem>().Single(x => x.Text == text);
						var itemIndex = dropDownList.Items.IndexOf(item);
						dropDownList.SelectedIndex = itemIndex;
					};
		}	
	}
}